#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
配置管理模块
"""

import os
from typing import Optional

class Config:
    """配置管理类"""
    
    def __init__(self):
        """初始化配置"""
        # 服务器配置
        self.HOST = os.getenv('HOST', 'your-server-host.com')
        
        # API接口配置
        self.GET_LINKS_API = os.getenv('GET_LINKS_API', f'https://{self.HOST}/api/get-group-links')
        self.SUBMIT_DATA_API = os.getenv('SUBMIT_DATA_API', f'https://{self.HOST}/api/submit-group-data')
        
        # API认证
        self.API_TOKEN = os.getenv('API_TOKEN', '')
        
        # 请求配置
        self.REQUEST_DELAY = float(os.getenv('REQUEST_DELAY', '2.0'))
        self.REQUEST_TIMEOUT = int(os.getenv('REQUEST_TIMEOUT', '30'))
        self.MAX_RETRIES = int(os.getenv('MAX_RETRIES', '3'))
        
        # 日志配置
        self.LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO')
        self.LOG_FILE = os.getenv('LOG_FILE', 'tg_scraper.log')
        
        # 第三方API配置
        self.TGSTAT_API_KEY = os.getenv('TGSTAT_API_KEY', '')
    
    def get_headers(self) -> dict:
        """获取请求头"""
        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
        }
        
        if self.API_TOKEN:
            headers['Authorization'] = f'Bearer {self.API_TOKEN}'
        
        return headers

# 创建全局配置实例
config = Config()
